package clientSocket;

import java.io.*;
import java.net.*;

import util.MessageFatorial;

public class ClientSocket {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws UnknownHostException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws UnknownHostException, IOException, 
		ClassNotFoundException {
		
		if (args.length <= 0) {
			System.out.println("Informe um valor!");
			System.exit(0);
		}
			
		int number = Integer.parseInt(args[0]);
		
        MessageFatorial men = new MessageFatorial();
        
        Socket socketCliente = new Socket("localhost", 9000); 
        
        men.setNumber(number);

        ObjectOutputStream fatInputServer  = new ObjectOutputStream(socketCliente.getOutputStream());
        ObjectInputStream  fatOutputServer = new ObjectInputStream(socketCliente.getInputStream());
        
        fatInputServer.writeObject(men);
        fatInputServer.flush();
        
        MessageFatorial fin = (MessageFatorial)fatOutputServer.readObject();
        
        System.out.println("%d! = " + fin.getResult());
        socketCliente.close(); 
	}

}
